package com.xuyanze.model;

import com.xuyanze.config.properties.ApiDocProperties;

import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Automatic generation by tools
 * dto: exchange data with view
 */
public class InterfaceDto {
	private String id;
	private String url;
	private String method;
	private String param;
	private String paramRemark;
	private String requestExam;
	private String responseParam;
	// 错误码，多个错误码使用,分割
	private String errorList;
	private String trueExam;
	private String falseExam;
	private Byte status;
	private String statusName;
	private String moduleId;
	private String moduleName;
	private String moduleUrl;
	private String interfaceName;
	private String remark;
	// 错误码，json
	private String errors;
	private String updateBy;
    private String createTimeStr;
    private String updateTimeStr;
	private String version;
	private Long sequence;
	private String header;
	private String fullUrl;
	private Integer monitorType;
	private String monitorText;
	private String monitorEmails;
	private Boolean isTemplate;
	private String projectId;
	private String projectName;
	private String remarkNoHtml;

	private String uniKey;

	/**
	 * 返回类型
	 */
	private String contentType;
    private String contentTypeName;
	/**
	 * 请求类型
	 */
	private String reqContentType;

    // 参数类型：FORM、CUSTOM
    private String paramType;

	public InterfaceDto(){}


	public static InterfaceDto build(ApiDocProperties p,String uri,String interfaceName,boolean wan){
		InterfaceDto dto = new InterfaceDto();
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String now= f.format(new Date());

		dto.setMethod("POST");
		dto.setParamRemark("[]");
		dto.setStatus((byte)1);
		dto.setStatusName("已上线");
		dto.setInterfaceName(interfaceName);
		dto.setErrors("[]");
		dto.setUpdateBy(String.format("userName：%s | trueName：%s",p.getUserName(),p.getTrueName()));
		dto.setCreateTimeStr(now);
		dto.setUpdateTimeStr(now);
		dto.setVersion("1.0");
		dto.setSequence(System.currentTimeMillis());
		dto.setHeader("[]");
		dto.setUrl(String.format("%s/%s%s",wan?p.getTestDomain():p.getTestIntranetIp() ,p.getRootPath(),uri));
		dto.setFullUrl(dto.getUrl());
		dto.setMonitorType(0);
		dto.setTemplate(false);
		dto.setContentType("application/json");
		dto.setContentTypeName("application/json");
		dto.setReqContentType("application/json");
		dto.setParamType("FORM");
		dto.setTemplate(false);
		dto.setRemark("<p>测试域名："+ (wan ? p.getTestDomain():p.getTestIntranetIp())+"</p>" +
				"\n" +
				"<p>正式环境域名："+(wan ? p.getProdDomain() : p.getProdIntranetIp())+"</p>");
		return dto;
	}


	public Map<String,String> toParamsMap(){
		Map<String,String> paramsMap = new HashMap<>();
		paramsMap.put("id",getId());
		paramsMap.put("url",getUrl());
		paramsMap.put("method",getMethod());
		paramsMap.put("param",getParam());
		paramsMap.put("paramRemark",getParamRemark());
		paramsMap.put("requestExam",getRequestExam());
		paramsMap.put("responseParam",getResponseParam());
		paramsMap.put("errorList",getErrorList());
		paramsMap.put("trueExam",getTrueExam());
		paramsMap.put("falseExam",getFalseExam());
		paramsMap.put("status",String.valueOf(getStatus()));
		paramsMap.put("statusName",getStatusName());
		paramsMap.put("moduleId",getModuleId());
		paramsMap.put("moduleName",getModuleName());
		paramsMap.put("moduleUrl",getModuleUrl());
		paramsMap.put("interfaceName",getInterfaceName());
		paramsMap.put("remark",getRemark());
		paramsMap.put("errors",getErrors());
		paramsMap.put("updateBy",getUpdateBy());
		paramsMap.put("createTimeStr",getCreateTimeStr());
		paramsMap.put("updateTimeStr",getUpdateTimeStr());
		paramsMap.put("version",getVersion());
		paramsMap.put("sequence",String.valueOf(getSequence()));
		paramsMap.put("header",getHeader());
		paramsMap.put("fullUrl",getFullUrl());
		paramsMap.put("monitorType",String.valueOf(getMonitorType()));
		paramsMap.put("monitorText",getMonitorText());
		paramsMap.put("monitorEmails",getMonitorEmails());
		paramsMap.put("isTemplate",String.valueOf(getTemplate()));
		paramsMap.put("projectId",getProjectId());
		paramsMap.put("projectName",getProjectName());
		paramsMap.put("remarkNoHtml",getRemarkNoHtml());
		paramsMap.put("uniKey",getUniKey());
		paramsMap.put("contentType",getContentType());
		paramsMap.put("contentTypeName",getContentTypeName());
		paramsMap.put("reqContentType",getReqContentType());
		paramsMap.put("paramType",getParamType());
		return paramsMap;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getParam() {
		return param;
	}

	public InterfaceDto setParam(String param) {
		this.param = param;
		return this;
	}

	public String getParamRemark() {
		return paramRemark;
	}

	public void setParamRemark(String paramRemark) {
		this.paramRemark = paramRemark;
	}

	public String getRequestExam() {
		return requestExam;
	}

	public void setRequestExam(String requestExam) {
		this.requestExam = requestExam;
	}

	public String getResponseParam() {
		return responseParam;
	}

	public InterfaceDto setResponseParam(String responseParam) {
		this.responseParam = responseParam;
		return this;
	}

	public String getErrorList() {
		return errorList;
	}

	public void setErrorList(String errorList) {
		this.errorList = errorList;
	}

	public String getTrueExam() {
		return trueExam;
	}

	public InterfaceDto setTrueExam(String trueExam) {
		this.trueExam = trueExam;
		return this;
	}

	public String getFalseExam() {
		return falseExam;
	}

	public InterfaceDto setFalseExam(String falseExam) {
		this.falseExam = falseExam;
		return this;
	}

	public Byte getStatus() {
		return status;
	}

	public void setStatus(Byte status) {
		this.status = status;
	}

	public String getStatusName() {
		return statusName;
	}

	public void setStatusName(String statusName) {
		this.statusName = statusName;
	}

	public String getModuleId() {
		return moduleId;
	}

	public InterfaceDto setModuleId(String moduleId) {
		this.moduleId = moduleId;
		return this;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	public String getModuleUrl() {
		return moduleUrl;
	}

	public void setModuleUrl(String moduleUrl) {
		this.moduleUrl = moduleUrl;
	}

	public String getInterfaceName() {
		return interfaceName;
	}

	public void setInterfaceName(String interfaceName) {
		this.interfaceName = interfaceName;
	}

	public String getRemark() {
		return remark;
	}

	public InterfaceDto setRemark(String remark) {
		this.remark = remark;
		return this;
	}

	public String getErrors() {
		return errors;
	}

	public void setErrors(String errors) {
		this.errors = errors;
	}

	public String getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy;
	}

	public String getCreateTimeStr() {
		return createTimeStr;
	}

	public void setCreateTimeStr(String createTimeStr) {
		this.createTimeStr = createTimeStr;
	}

	public String getUpdateTimeStr() {
		return updateTimeStr;
	}

	public void setUpdateTimeStr(String updateTimeStr) {
		this.updateTimeStr = updateTimeStr;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public Long getSequence() {
		return sequence;
	}

	public void setSequence(Long sequence) {
		this.sequence = sequence;
	}

	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	public String getFullUrl() {
		return fullUrl;
	}

	public void setFullUrl(String fullUrl) {
		this.fullUrl = fullUrl;
	}

	public Integer getMonitorType() {
		return monitorType;
	}

	public void setMonitorType(Integer monitorType) {
		this.monitorType = monitorType;
	}

	public String getMonitorText() {
		return monitorText;
	}

	public void setMonitorText(String monitorText) {
		this.monitorText = monitorText;
	}

	public String getMonitorEmails() {
		return monitorEmails;
	}

	public void setMonitorEmails(String monitorEmails) {
		this.monitorEmails = monitorEmails;
	}

	public Boolean getTemplate() {
		return isTemplate;
	}

	public void setTemplate(Boolean template) {
		isTemplate = template;
	}

	public String getProjectId() {
		return projectId;
	}

	public InterfaceDto setProjectId(String projectId) {
		this.projectId = projectId;
		return this;
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	public String getRemarkNoHtml() {
		return remarkNoHtml;
	}

	public void setRemarkNoHtml(String remarkNoHtml) {
		this.remarkNoHtml = remarkNoHtml;
	}

	public String getUniKey() {
		return uniKey;
	}

	public void setUniKey(String uniKey) {
		this.uniKey = uniKey;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getContentTypeName() {
		return contentTypeName;
	}

	public void setContentTypeName(String contentTypeName) {
		this.contentTypeName = contentTypeName;
	}

	public String getReqContentType() {
		return reqContentType;
	}

	public void setReqContentType(String reqContentType) {
		this.reqContentType = reqContentType;
	}

	public String getParamType() {
		return paramType;
	}

	public void setParamType(String paramType) {
		this.paramType = paramType;
	}

	public static void main(String[] args) {
		Field[] declaredFields = InterfaceDto.class.getDeclaredFields();
		for (Field field : declaredFields){
			String name = field.getName();

			StringBuilder sb = new StringBuilder(name);
			char c = name.toUpperCase().toCharArray()[0];
			sb.replace(0,1,String.valueOf(c));
			sb.insert(0,"get");

//			System.out.println(String.format("paramsMap.put(\"%s\",%s());",name,sb.toString()));
		}


	}

}
